/*************************************************
Author: Aven 
Date: 2/25/2013
Description:
Notes: 
*************************************************/

#ifndef __CDiceConfig_h__
#define __CDiceConfig_h__

#include "CTArray.h"
#include "../maindef.h"
#include "commclass.h"

/*
    ERROR_CONSUME_CONTRI_ADD_EMPTY_CONFIG   =  , //空消耗贡献度配置
    ERROR_CONTRIBUTE_TIMES                  =  , //错误的贡献度消耗次数
    ERROR_CONSUME_CONTRI_DUPLICATED_CONFIG  =  , //重复的贡献度消耗配置
    ERROR_MAGIC_DOOR_LEVEL_ADD_EMPTY_CONFIG =  , //魔界门等级配置为空
    ERROR_MAGIC_DOOR_LEVEL                  =  , //魔界门等级错误
    ERROR_MAGIC_DOOR_LEVEL_DUPLICATED_CONFIG=  , //重复的魔界门等级配置
    ERROR_NOT_ENOUGH_CONTRIBUTE             =  , //家族贡献度不够充能
    ERROR_REJECT_PAY_CLAN_JOIN_DAY          =  , //入家族当天不能充能
    ERROR_MAGIC_DOOR_MAX_LEVEL_NOT_CONTRI   =  , //魔界门满级，不能充能

    ERROR_BEYOND_BUY_COUNTS                 =  , //超过最大购买次数

    //格子类型
    CONST_GRID_TYPE_LEVEL_START             = 0, //每一层的起始格子
    CONST_GRID_TYPE_AWARD                   = 1, //奖励
    CONST_GRID_TYPE_ADD_ONE_TIMES           = 2, //投骰次数+1
    CONST_GRID_TYPE_SHAKE_TWO_DICE          = 3, //投掷2个骰子

    CONST_DICE_GRIDS_ONE_LAYER  = 6,        //每层的格子数
    CONST_DICE_AWARD_BASE_RATE  = 10,       //根据级别奖励的系数基数
    CONST_DAILY_DICE_COUNTS = 10,           //每日可以免费投骰子的次数
    CONST_DAILY_DICE_BUY_COUNTS = 10,       //每日可以购买投骰子的次数
    MAX_DICE_GRID_NUMS      = 120,          //格子的最大个数, 6*20 = 120
    MAX_DICE_PAY_NUMS       = 10,           //可以金币购买的最大次数
    MAX_DICE_LEVEL_NUMS     = 20,           //最多层级数

class CFamilyDiceData:public CTCodeObject
{
public:
    CFamilyDiceData()
    {
        Clear();
    }

public:
    CDailyReflushShort _sGridId;             //当前格子位置
    CDailyReflushShort _sDiceRestCounts;     //剩余可以投骰子的次数
    CDailyReflushShort _sBuyCounts;          //今日金币购买的次数

    CDailyReflushShort _sDailyRepution;     //今日获得的声望
    CDailyReflushShort _sDailySilver;       //今日获得的银币
    CDailyReflushShort _sDailyExper;        //今日获得的经验

public:
    void Clear()
    {
        _sGridId.SetDefault(0);
        _sDiceRestCounts.SetDefault( CONST_DAILY_DICE_COUNTS );
        _sBuyCounts.SetDefault( CONST_DAILY_DICE_BUY_COUNTS );

        _sDailyRepution.SetDefault( 0 );
        _sDailySilver.SetDefault( 0 );
        _sDailyExper.SetDefault( 0 );
    }
};

BEGIN_CODE_CONVERT(CFamilyDiceData)
CODE_CONVERT(_sGridId)
CODE_CONVERT(_sDiceRestCounts)
CODE_CONVERT(_sBuyCounts)
CODE_CONVERT(_sDailyRepution)
CODE_CONVERT(_sDailySilver)
CODE_CONVERT(_sDailyExper)
END_CODE_CONVERT(CFamilyDiceData);
*/

class CFamilyDiceConfig;


typedef struct 
{
    int iAwardItemType;
    int iAwardItemId;
    int iAwardNum;
}TAward;

//闯关格子配置
class CDiceAwardConfigData
{
public:
    CDiceAwardConfigData()
        :_bHasConfig(false)
    {
    }

    virtual ~CDiceAwardConfigData()
    {
    }

    void Clear() {_bHasConfig = false;}
    bool HasConfig() const {return _bHasConfig;}

public:
    bool _bHasConfig;

    short iGridId;          //闯关格子id
    short iGridType;        //格子类型
    TAward  award;          //奖励物品
};

//够买骰子配置
class CPayDiceConfigData
{
public:
    CPayDiceConfigData()
        :_bHasConfig(false)
    {
    }

    virtual ~CPayDiceConfigData()
    {
    }

    void Clear() {_bHasConfig = false;}
    bool HasConfig() const {return _bHasConfig;}

public:
    bool _bHasConfig;

    short iTimes;           //购买次数
    int iNeedGold;     //当前次数需要金币数
};

//闯关层级奖励配置
class CDiceLevelAwardConfigData
{
public:
    CDiceLevelAwardConfigData()
        :_bHasConfig(false)
    {
    }

    virtual ~CDiceLevelAwardConfigData()
    {
    }

    void Clear() {_bHasConfig = false;}
    bool HasConfig() const {return _bHasConfig;}

public:
    bool _bHasConfig;

    short iLevel;           //闯关的层级
    CTLib::CTArray<TAward, MAX_DICE_LEVEL_AWARD_NUM>   _aTAwards;  //闯关层级的奖励
};

//根据等级奖励的系数
class CDiceAwardRateData
{
public:
    CDiceAwardRateData()
        :_bHasConfig(false)
    {
    }

    virtual ~CDiceAwardRateData()
    {
    }

    void Clear() {_bHasConfig = false;}
    bool HasConfig() const {return _bHasConfig;}

public:
    bool _bHasConfig;

    short iDiceLevel;           //闯关层级
    short iSilverAwardRate;     //银币奖励系数,千分比
    short iExperAwardRate;     //经验奖励系数,千分比
    short iContribuAward;     //贡献度
};

class CDropItemData;
class CDropItem;

//家族闯关配置
class CFamilyDiceConfig
{
public:
	CFamilyDiceConfig() 
        :_iMaxGridID(0)
    {
        _astDiceRankAward.Clear();
	}

	virtual ~CFamilyDiceConfig() 
    {
	}

    int Init();

    int AddDiceGridConfig( CDiceAwardConfigData& stData );
    int GetDiceGridConfig( short iGridId, CDiceAwardConfigData& stData );
    int GetGridCount() { return _iMaxGridID;}

    int AddPayDiceConfig( CPayDiceConfigData& stData);
    int GetPayDiceConfig( short iTimes, CPayDiceConfigData& stData);

    //int AddLevelAwardConfig( CDiceLevelAwardConfigData& stData );
    int AddLevelAwardConfig( short iLayer, TAward& stData );
    int GetLevelAwardConfig( short iLevel, CDiceLevelAwardConfigData& stData );

    int AddAwardRateConfig( CDiceAwardRateData& stData );
    int GetAwardRateConfig( short iDiceLevel, CDiceAwardRateData& stData );

    int AddRankConfig(int iRank, CDropItemData & stData );
    int GetRankConfig(int iRank, CDropItemData & stData );

private:
    int _iMaxGridID;
    CTLib::CTArray<CDiceAwardConfigData, MAX_DICE_GRID_NUMS+1>              _astDiceGridConfigs;        //所有格子配置
    CTLib::CTArray<CPayDiceConfigData, MAX_DICE_PAY_NUMS+1>                 _astDicePayConfigs;         //购买次数金币配置
    CTLib::CTArray<CDiceLevelAwardConfigData, MAX_DICE_LEVEL_NUMS+1>        _astDiceLevelConfigs;       //格子层级奖励配置
    CTLib::CTArray<CDiceAwardRateData, MAX_ROLE_LEVEL+1>        _astDiceAwardRateConfigs;               //据等级奖励的系数配置
public:
    CTLib::CTArray<CDropItemData, MAX_DICE_RANK_SIZE>       _astDiceRankAward;                //闯关排行榜奖励。周日24点发放
};

#endif // __CDiceConfig_h__

